CC=g++
SOURCES=bbar.cpp AnalyzeSA.h filters.h jetclustering.h observables.h Clustering.h hWW.h modifiers.h utility.h LHEF.h mt2_bisect.h dijet.h 
EXECUTABLE=bbar.exe
#OBJECTS=bbar.o AnalyzeSA.h filters.o jetclustering.o observables.o Clustering.o hWW.o modifiers.o utility.o LHEF.o mt2_bisect.o dijet.o
OBJECTS=bbar.o 
#EXROOTPATH=./ExRootAnalysis/  

ifeq ($(shell uname),Darwin)
DYLIBEXT=dylib
ifeq  ($(shell uname -m),i386)
endif
ifeq  ($(shell uname -m),Power Macintosh)
endif
endif
ifeq ($(shell uname),Linux)
DYLIBEXT=so
endif

CFLAGS=-c
LDFLAGS=`root-config --libs` -fopenmp
ROOTCFLAGS=`root-config --cflags`

all: $(SOURCES) $(EXECUTABLE)

os: ExROOT dictionaries

$(EXECUTABLE): $(OBJECTS)
	$(CC) $(LDFLAGS) $(OBJECTS) -L./ExRootAnalysis/lib/ -lExRootAnalysis -o $@

bbar.o: libExRootAnalysis.$(DYLIBEXT) vvectordictionary_c.so vectordictionary_c.so libExRootAnalysis.so $(SOURCES)

#	$(CC) $(CFLAGS) bbar.cpp -I$(EXROOTPATH) $(ROOTCFLAGS)
	$(CC) $(CFLAGS) bbar.cpp -fopenmp $(ROOTCFLAGS)
#	$(CC) $(CFLAGS) bbar.cpp  $(ROOTCFLAGS)

libExRootAnalysis.so:
	tar zxf ExRootAnalysis_V1.0.7.tar.gz; cd ExRootAnalysis; make clean; rm -rf lib tmp; cp Makefile OrigMakefile; cp ../exrootmakefile Makefile; make DllSuf=$(DYLIBEXT); make; cd ..;ln -fs ./ExRootAnalysis/lib/libExRootAnalysis.so .;  ln -fs ./ExRootAnalysis/lib/libExRootAnalysis.dylib .;

libExRootAnalysis.dylib:
	make libExRootAnalysis.so

vvectordictionary_c.so:
	root.exe -b -l -q 'build.C("vvectordictionary.c")'

vectordictionary_c.so:
	root.exe -b -l -q 'build.C("vectordictionary.c")'

dictionaries:
	make vvectordictionary_c.so; make vectordictionary_c.so;
ExROOT:
	make libExRootAnalysis.so;
############
# devel unfinished things
############
utilities:
	cd utils; ./compile_slimmerROOT.sh; cd ..;

clean:
	rm *.o $(EXCUTABLE)


sick: sick.o
	$(CC) $(LDFLAGS) sick.o -L./ -lExRootAnalysis -o sick.exe

sick.o: libExRootAnalysis.$(DYLIBEXT) vvectordictionary_c.so vectordictionary_c.so libExRootAnalysis.so sick.cpp

	$(CC) $(CFLAGS) sick.cpp -I$(EXROOTPATH) $(ROOTCFLAGS)

ClusterROOT: ClusterExRootLHEFConverter.o
	$(CC) $(LDFLAGS)  ClusterExRootLHEFConverter.o -L./ -lExRootAnalysis -o ClusterExRootLHEFConverter.exe 

ClusterExRootLHEFConverter.o: libExRootAnalysis.$(DYLIBEXT) vvectordictionary_c.so vectordictionary_c.so libExRootAnalysis.so ClusterExRootLHEFConverter.cpp

	$(CC) $(CFLAGS) ClusterExRootLHEFConverter.cpp -I$(EXROOTPATH) $(ROOTCFLAGS)
